<div id="equipmentnames" style="display:none;">    
    <%= @EquipmentNames %>
</div>
<div id="equipmentcategories" style="display:none">
    <%= @EquipmentCategories %>
</div>
<div id="equipmentdescriptions" style="display:none">
    <%= @EquipmentDescriptions %>
</div>
<% if params[:act] %>
    <% if params[:act] == "create" %>
        <script type="text/javascript">
            $(function() {
                $('#add_note_dialog').dialog();
                $('#add_note_dialog').dialog( "option", "width", 365);
            });
        </script>
        <div id="add_note_dialog" title="Creating a note&nbsp;">
                 <%= render(:partial => "note/create", :id=>params[:id], :con => params[:con]) %>
        </div>
    <% elsif params[:act] == "view"%>
        <script type="text/javascript">
            $(function() {
                $('#view_note_dialog').dialog();
                $('#view_note_dialog').dialog( "option", "width", 365);
            });
        </script>
        <div id="view_note_dialog" title="Viewing note&nbsp;">
                 <%= render(:partial => "note/view", :id => params[:id], :rediract => "list_all", :redircont => "equipment") %>
        </div>
    <% elsif params[:act] == "edit"%>
        <script type="text/javascript">
            $(function() {
                $('#edit_note_dialog').dialog();
                $('#edit_note_dialog').dialog( "option", "width", 365);
            });
        </script>
        <div id="edit_note_dialog" title="Editing note&nbsp;">
                 <%= render(:partial => "note/edit", :id => params[:id], :rediract => "list_all", :redircont => "equipment") %>
        </div>
    <% end %>
<% end %>


<% form_for :equipment, :url => { :action => "list_all" } do |f| %>
<table>
 <tr>
  <td>
    Name 
    <%= text_field 'equipment', 'lookup_name', :size => 30 %>
  </td>
  <td>
    Description
    <%= text_field 'equipment', 'lookup_description', :size=>30 %>
  </td>
  <td>
    Category
    <%= text_field 'equipment', 'lookup_category', :size => 30 %>
  </td>
  <td>
  <%= submit_tag "Filter results" %>
  </td>
 </tr>
</table>
<% end %>


<table id="equipment_table" class="tablesorter">
<thead>
    <tr>
      <th>Name</th>
      <th>Size</th>
      <th>Weekend Cost</th>
      <th>Weekday Cost</th>
      <th>Date Added</th>
      <th>Description</th>      
      <th>Category</th>   
      <th>Notes</th>   
    </tr>
</thead>
<tbody id="tablecontent" overflow: scroll;">
<% @equip.each do |eE| %>
    <tr>
        <td>
            <%= eE.name %>
        </td>
        <td>
            <%= eE.size %>
        </td>        
        <td>
            <%= eE.weekend_cost %>
        </td>
        <td>
            <%= eE.weekday_cost %>
        </td>
        <td>
            <%= eE.date_added.to_s[0..eE.date_added.to_s.length-14] %>
        </td>
        <td>
            <%= eE.description %>
        </td>
        <td>
            <% if Category.find_by_id(eE.category) -%>
                <%= Category.find_by_id(eE.category).name %>
            <% end -%>
        </td>
        <td>
            <% notes = Note.find_all_by_con_and_foreignkey("equipment", eE.id) %>

            <% if notes -%>                
                    <% notes.each do |note| %>
                        <%= link_to image_tag("/images/Icons/note.jpg", :style=>"border:none;" ), {:action => "list_all", :act => "view", :id => note.id, :redircont => "equipment", :rediract => "list_all"} %>
                    <% end %>              
            <% end -%>
        </td>
        <td>
            <%= link_to "Add Note", {:action => "list_all", :act => "create", :con => "equipment", :id => eE.id}%>
        </td>
    </tr>
<% end %>
</tbody>
</table>
<script type="text/javascript">
    $("#equipment_table").tablesorter();
    $('#tablecontent').css('height', $(window).height() - 160 + 'px');

    var equipcategs = $("#equipmentcategories").html().split("☺");
    var equipnames = $("#equipmentnames").html().split("☺");
    var equipdescs = $("#equipmentdescriptions").html().split("☺");

    $('#equipment_lookup_name').autocomplete(equipnames, {
		matchContains: true
    });
    $('#equipment_lookup_description').autocomplete(equipdescs, {
		matchContains: true
    });
    $('#equipment_lookup_category').autocomplete(equipcategs, {
		matchContains: true
    });
</script>
